<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :option="option"
        :data="tableList"
        :table-loading="tableLoading"
        :page="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-change="searchChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-del="handleDelete"
      >
        <template slot-scope="scope" slot="menuLeft">
          <el-button type="primary"
                     icon="el-icon-plus"
                     size="small"
                     @click.stop="handleAdd()">新增</el-button>
        </template>

        <template
          slot="menu"
          slot-scope="scope">
          <el-button
            v-if="permissionBtn.pre_report_edit"
            type="text"
            size="small"
            icon="el-icon-edit"
            @click="handleStart(scope.row,scope.index)">查看详情
          </el-button>
          <el-button
            v-if="permissionBtn.pre_report_del"
            type="text"
            size="small"
            icon="el-icon-delete"
            @click="handleDelete(scope.row,scope.index)">删除
          </el-button>
          <el-button
            v-if="permissionBtn.pre_report_out && scope.row.commType == 'OUT'"
            type="text"
            size="small"
            icon="el-icon-edit"
            @click="handleStart(scope.row,scope.index)">接出测试
          </el-button>
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>
<script>
  import { fetchList, putObj,delObj } from '@/api/pre/report'
  import { option } from '@/const/crud/pre/report'
  import { mapGetters } from 'vuex'
  export default {
    name: 'Node',
    data(){
      return{
        option: option,
        tableList: [],
        tableLoading: false,
        searchForm: {},
        page: {
          total: 0,
          currentPage: 1,
          pageSize: 20,
        },

      }
    },
    computed: {
      ...mapGetters(['permissions']),
      permissionBtn(){
        return {
          pre_report_edit: this.permissions['pre_report_edit'],
          pre_report_add: this.permissions['pre_report_add'],
          pre_report_del: this.permissions['pre_report_del'],
          pre_report_out: this.permissions['pre_report_out']
        }
      }
    },
    created() {
    },

    methods: {
      getList(page, params){
        this.tableLoading = true
        fetchList(Object.assign({
          current: page.currentPage,
          size: page.pageSize
        }, params, this.searchForm)).then(response => {
          this.tableList = response.data.data.records
          this.page.total = response.data.data.total
          this.tableLoading = false
        })
      },
      sizeChange(pageSize) {
        this.page.pageSize = pageSize
      },
      currentChange(current) {
        this.page.currentPage = current
      },
      refreshChange() {
        this.getList(this.page)
      },
      searchChange(param,done) {
        this.searchForm = param
        this.page.currentPage = 1
        this.getList(this.page, param)
        done()
      },
      handleAdd(){
      },
      //删除
      handleDelete: function(row, index) {
        this.$confirm('是否确认删除' + row.systemName + '的通讯配置？', '提示', {
          type: 'warning'
        })
          .then(() => {
            return delObj(row.sysId)
          })
          .then((res) => {
            this.$message.success('删除成功')
            this.refreshChange()
          })
          .catch(() => {})
      },

      getTodoById: function (state) {
        function f(id) {
          return state.todos.find(todo => todo.id === id)
        }
      }

    }
  }
</script>
